package com.qhyiyun.baseweb.serivice;

import com.qhyiyun.baseweb.model.CommentWall;
import com.qhyiyun.baseweb.model.Users;
import com.qhyiyun.baseweb.repository.CommentWallRepository;
import com.qhyiyun.baseweb.repository.UserRepository;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class BaseService {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private CommentWallRepository commentWallRepository;
    @Cacheable(value = "vsId", key = "#visitId")
   public String saveId(String visitId){
        return visitId;
   }
    @CachePut(value = "vsId", key = "#userId")
    public void updateVsId(String userId) {
        // 更新用户逻辑，比如保存到数据库
        // 这个方法的返回值（可能是更新后的User对象或void）会被放入缓存
    }
    public Users qryByVsId(String userVsId){
       return userRepository.findByuserVsId(userVsId);
    }
    public Users save(Users users){
        return userRepository.saveAndFlush(users);
    }
    public List<Users> qryAll(){
        return userRepository.findAll();
    }
    public List<CommentWall> qryAllAna(){
        return commentWallRepository.findAll();
    }
    public CommentWall saveAna(CommentWall cmt){
        return commentWallRepository.saveAndFlush(cmt);
    }
}
